package com.yuexunit.operationman.nbsy.module.Catheter.ui;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.base.BaseKJActivity;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.Catheter.CatheterContracts;
import com.yuexunit.operationman.nbsy.module.Catheter.bean.CatheterBean;
import com.yuexunit.operationman.nbsy.module.Catheter.model.impl.CatheterDetailModel;
import com.yuexunit.operationman.nbsy.module.Catheter.presenter.ICatheterDetailPresenter;
import com.yuexunit.operationman.nbsy.module.Catheter.presenter.impl.CatheterDetailPresenter;
import com.yuexunit.operationman.nbsy.module.Catheter.ui.view.ICatheterDetailView;
import com.yuexunit.operationman.nbsy.widget.LoadingDialog;

import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chenss on 2017/12/27 0027.
 */

public class Act_Catheter_Main extends BaseKJActivity implements ICatheterDetailView {

    @Bind(R.id.titlebar_tv_title)
    TextView titlebarTvTitle;
    @Bind(R.id.titlebar_img_back)
    ImageView titlebarImgBack;
    @Bind(R.id.usr_head)
    ImageView usrHead;
    @Bind(R.id.usr_name)
    TextView usrName;
    @Bind(R.id.usr_age)
    TextView usrAge;
    @Bind(R.id.usr_gender)
    TextView usrGender;
    @Bind(R.id.preops_diagnosis)
    TextView preopsDiagnosis;
    @Bind(R.id.recipe_id)
    TextView recipeId;
    @Bind(R.id.hisPatientNo)
    TextView hisPatientNo;

    ICatheterDetailPresenter presenter;

    LoadingDialog loadingDialog;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_catheter_main);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        setTitle();
        loadingDialog = new LoadingDialog(this);
        presenter = new CatheterDetailPresenter(this,new CatheterDetailModel());
    }

    @Override
    public void onResume(){
        super.onResume();
        Map<String, String> params = new HashMap<>();
        params.put("operationNo", PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_OPERATION_ID)+"");
        presenter.getCatheterDate(params);
    }

    private void setTitle()
    {
        titlebarTvTitle.setText("导尿管使用表");
    }

    @OnClick({R.id.titlebar_img_back, R.id.catheter_use, R.id.catheter_sign, R.id.catheter_preview})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.titlebar_img_back:
                finish();
                break;
            case R.id.catheter_use:
                startActivity(new Intent(aty, Act_Catheter_Use.class));
                break;
            case R.id.catheter_sign:
                startActivity(new Intent(aty, Act_Catheter_Sign.class));
                break;
            case R.id.catheter_preview:
                startActivity(new Intent(aty, Act_Catheter_Preview.class));
                break;
        }
    }

    @Override
    public void getCatheterDate(CatheterBean catheterBean) {
        if(catheterBean.getCode() == 200)
        {
            AppConfig.CATHETERBEAN =catheterBean;
            usrName.setText(AppConfig.CATHETERBEAN.getObject().getCatheter().getPatientName());
            usrAge.setText(AppConfig.CATHETERBEAN.getObject().getCatheter().getPatientAge()+"");
            if(AppConfig.CATHETERBEAN.getObject().getCatheter().getPatientSex().equals("1")) {
                usrGender.setText("男");
            }else if(AppConfig.CATHETERBEAN.getObject().getCatheter().getPatientSex().equals("2"))
            {
                usrGender.setText("女");
            }
            else {
                usrGender.setText("不详");
            }
            preopsDiagnosis.setText(AppConfig.CATHETERBEAN.getObject().getCatheter().getPreOperation());
            recipeId.setText(AppConfig.CATHETERBEAN.getObject().getCatheter().getBedNo());
            hisPatientNo.setText(AppConfig.CATHETERBEAN.getObject().getCatheter().getInHospitalNo());

            if(AppConfig.CATHETERBEAN.getObject().getCatheterItemList() == null)
            {
                AppConfig.CATHETERBEAN.getObject().setCatheterItemList(CatheterContracts.CATHETER_ITEM_LIST_ENTITIES_NEW(this));
            }
        }
    }

    @Override
    public void loadingDialogStatus(int status) {
        switch (status) {
            case AppConfig.SHOW_DIALOG:
                loadingDialog.setCanceledOnTouchOutside(false);
                loadingDialog.show();
                break;
            case AppConfig.DISMISS_DIALOG:
                loadingDialog.dismiss();
                break;

        }
    }
}
